/*
    socklibpp library
    Copyright (C) 2005  Daniel K. O. <danielosmari at users.sf.net>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/


/**     \hideinitializer
*/

#ifndef SOCKCOMMON_H
#define SOCKCOMMON_H

/**     \file sockcommon.h
        \brief Some basic defines and typedefs
*/

/* TODO (DanielKO#3#): Separate some #includes and #defines in other
                       headers (e.g. sockbase.h and sockaddr.h) */


#ifdef WIN32


#include <winsock2.h>

typedef SOCKET          socket_type;
typedef int             socklen_t;
typedef unsigned int    uint32_t;
typedef unsigned short  uint16_t;

/**     \if dummy
*/
#define __GET_LAST_ERROR        WSAGetLastError()


/**     \endif
*/

#else
// *nix
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <netinet/tcp.h>
#include <sys/select.h>

#include <cerrno>

typedef int     socket_type;

#define __GET_LAST_ERROR        errno
#define INVALID_SOCKET          -1
#define SOCKET_ERROR            -1
#define closesocket(x)          close(x)
#define ioctlsocket(x, y, z)    ioctl(x, y, z)

// let's define here all the BSD socket possible errors as Winsock defines

/**     \if dummy
*/
#define WSAEINTR                EINTR
#define WSAEBADF                EBADF
#define WSAEACCES               EACCES
#define WSAEFAULT               EFAULT
#define WSAEINVAL               EINVAL
#define WSAEMFILE               EMFILE
#define WSAEWOULDBLOCK          EWOULDBLOCK
#define WSAEINPROGRESS          EINPROGRESS
#define WSAEALREADY             EALREADY
#define WSAENOTSOCK             ENOTSOCK
#define WSAEDESTADDRREQ         EDESTADDRREQ
#define WSAEMSGSIZE             EMSGSIZE
#define WSAEPROTOTYPE           EPROTOTYPE
#define WSAENOPROTOOPT          ENOPROTOOPT
#define WSAEPROTONOSUPPORT      EPROTONOSUPPORT
#define WSAESOCKTNOSUPPORT      ESOCKTNOSUPPORT
#define WSAEOPNOTSUPP           EOPNOTSUPP
#define WSAEPFNOSUPPORT         EPFNOSUPPORT
#define WSAEAFNOSUPPORT         EAFNOSUPPORT
#define WSAEADDRINUSE           EADDRINUSE
#define WSAEADDRNOTAVAIL        EADDRNOTAVAIL
#define WSAENETDOWN             ENETDOWN
#define WSAENETUNREACH          ENETUNREACH
#define WSAENETRESET            ENETRESET
#define WSAECONNABORTED         ECONNABORTED
#define WSAECONNRESET           ECONNRESET
#define WSAENOBUFS              ENOBUFS
#define WSAEISCONN              EISCONN
#define WSAENOTCONN             ENOTCONN
#define WSAESHUTDOWN            ESHUTDOWN
#define WSAETOOMANYREFS         ETOOMANYREFS
#define WSAETIMEDOUT            ETIMEDOUT
#define WSAECONNREFUSED         ECONNREFUSED
#define WSAELOOP                ELOOP
#define WSAENAMETOOLONG         ENAMETOOLONG
#define WSAEHOSTDOWN            EHOSTDOWN
#define WSAEHOSTUNREACH         EHOSTUNREACH
#define WSAHOST_NOT_FOUND       HOST_NOT_FOUND
#define WSATRY_AGAIN            TRY_AGAIN
#define WSANO_RECOVERY          NO_RECOVERY
#define WSANO_DATA              NO_DATA

/**     \endif
*/


#endif



#endif
